﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Steamrunner
{
    class InputManager : GameComponent
    {
        private KeyboardState currentKeyState, lastKeyState;

        public InputManager(Game game)
            : base(game)
        {
        }

        public bool IsDown(Keys key)
        {
            return currentKeyState.IsKeyDown(key);
        }

        public bool JustPressed(Keys key)
        {
            return currentKeyState.IsKeyDown(key) && lastKeyState.IsKeyUp(key);
        }

        public bool JustReleased(Keys key)
        {
            return currentKeyState.IsKeyUp(key) && lastKeyState.IsKeyDown(key);
        }

        public override void Update(GameTime gameTime)
        {
            lastKeyState = currentKeyState;
            currentKeyState = Keyboard.GetState();
            
            base.Update(gameTime);
        }
    }
}
